package bankapp;

import frmsystem.*;

import java.util.Date;

import bankapp.util.BankSystemConstants;

public class BankCreator extends Creator{

	@Override
	public IEntry createTransaction(IParty party, IAccount account, int transactionType, double amount) {
		
		Entry entry = null;
				
		if (transactionType==BankSystemConstants.TRANSACTION_DEPOSIT) {
			entry = new Deposit(account);
			entry.setAmount(amount);
			entry.setDate(new Date());
			
			if (party.getType() == BankSystemConstants.PARTY_ORGANIZATION)
				entry.setEvent(new OrgDeposit());
			else if (party.getType() == BankSystemConstants.PARTY_PERSON)
				entry.setEvent(new PersonDeposit());
				
		} else if (transactionType==BankSystemConstants.TRANSACTION_WITHDRAW) {
			entry = new Withdraw(account);
			entry.setAmount(amount);
			entry.setDate(new Date());

			if (party.getType() == BankSystemConstants.PARTY_ORGANIZATION)
				entry.setEvent(new OrgWithdraw());
			else if (party.getType() == BankSystemConstants.PARTY_PERSON)
				entry.setEvent(new PersonWithdraw());			
		}		
		return entry;
	}

	@Override
	public IAccount createAccount(String accountNo, int accType) {
		
		if(accType==BankSystemConstants.ACCOUNT_CHECKING){
			Account checking_account = new Checking();
			checking_account.setAccountNo(accountNo);
			checking_account.setInterestRate(BankSystemConstants.INTEREST_RATE);
			checking_account.setCurrentAmmount(0);
			return checking_account;
		}
		if(accType==BankSystemConstants.ACCOUNT_SAVINGS){
			Account saving_account = new Saving();
			saving_account.setAccountNo(accountNo);
			saving_account.setInterestRate(BankSystemConstants.ZERO_INTEREST_RATE);
			saving_account.setCurrentAmmount(0);
			return saving_account;
		}		
		return null;
	}

}
